package com.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.springcloud.entity.UserEntity;
import com.springcloud.repository.UserRepository;

@RestController
public class UserController {

	@Autowired
	private UserRepository userRepository;

	@GetMapping("/get/{id}")
	public UserEntity get(@PathVariable Long id) {
		UserEntity user = userRepository.getOne(id);
		System.out.println("user:" + user);
		return user;
	}

	@PostMapping("/post/{id}")
	public UserEntity post(@PathVariable Long id) {
		UserEntity user = userRepository.getOne(id);
		System.out.println("user:" + user);
		return user;
	}

	@GetMapping("/list")
	public List<UserEntity> list() {
		List<UserEntity> list = userRepository.findAll();
		return list;
	}
}
